/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ssm.changeunit;

import com.ssm.changeunit.persistance.ChangeUnitItemDAO;
import com.ssm.changeunit.persistance.ChangeUnitItemDTO;
import com.ssm.changeunit.persistance.PersistanceException;

/**
 *
 * @author 시리우스
 */
public class ChangeUnitItemFactory extends AbstractFactory {
    @Override
    public ChangeUnitItem createProduct(String changeUnitItemId) throws CreateException {
        try {
            ChangeUnitItemDAO changeUnitItemDAO = new ChangeUnitItemDAO();
            
            ChangeUnitItemDTO changeUnitItemDTO = changeUnitItemDAO.find(changeUnitItemId);
            
            if(changeUnitItemDTO == null) {
                changeUnitItemDTO = new ChangeUnitItemDTO();
                
                changeUnitItemDTO.setChangeUnitItemId(changeUnitItemId);
                
                changeUnitItemDAO.insert(changeUnitItemDTO);
            }
            
            return new ChangeUnitItem(changeUnitItemId);
        }
        catch(PersistanceException ex) {
            throw new CreateException("ChangeUnitItem을 생성하는데 실패했습니다.", ex);
        }
    }
}